home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 7.1 KB | 195 lines | [TEXT/GEOL] |
- Item 0536839 11-Dec-90 11:55PST
-
- From: DAWSON.M Dawson, Mark
-
- To: CSX.ACCOUNT1 CSX Technology, Scott Steffan,PRT
- MACAPP.TECH$ MacApp Technical
-
- ------------------------------------------------------------------------------
-
- Sub: Re: IApplicaiton & splash…
-
- Thomas,
-
- Below is code (C++) that we use for our splash screen (drawn in our
- IApplication). Our splash screen draws a "progress" bar, that is controlled
- from the application. Clicking on the splash screen makes it go away. Its not
- perfect, but it does work.
-
- Hope this helps,
-
- Mark
- ------------------- cut here, if you don't want to view code ------------------
- ----------- class definitions -------------------
- // ==================================================================
- class TSplashScreen { // don't want this handle-based, so don't sub-class it
- DialogRecordfSplashDlogRecord; // holds the dialog record (we want it in our
- // memory, otherwise it will be allocated in the regular heap && will
- // fragment the memory.
- short fItemType; // user dialog item type for the incrementing bar
- Handle fItem; // item # for splash screen bar
- Handle fControlHandle; // handle to
- short fNumInc; // #of times this is going to be called
- short fCount; // #of times this has been called
- RectfBarPiece[kMaxNumSplashScreenCalls];// array of bar pieces to draw
- RectfBar; // total bar size (from resource)
- Boolean fWantGoAwayScreen;
- public:
- TSplashScreen( short num_sections, Boolean want_goaway_screen = FALSE);
- inline ~TSplashScreen() { CloseDialog((DialogPtr)&fSplashDlogRecord); }
- virtual pascal void UpdateSplashScreen(); // calls the draw dialog routine
- };
- ----------- resources -------------------
- // splash screen resources
- resource 'DLOG' (kSplashID, "Splash Screen", purgeable) {
- {72, 40, 182, 472},
- dBoxProc,
- invisible,
- noGoAway,
- 0x0,
- kSplashID,
- "Splash"
- };
-
- resource 'DITL' (1300, "Splash Screen", purgeable) {
- { /* array DITLarray: 4 elements */
- /* [1] */
- {78, 88, 92, 388},
- UserItem {
- disabled
- },
- /* [2] */
- {17, 16, 49, 48},
- Icon {
- disabled,
- 1300
- },
- /* [3] */
- {23, 152, 39, 312},
- StaticText {
- disabled,
- "Loading MacTest™..."
- },
- /* [4] */
- {41, 152, 57, 312},
- StaticText {
- disabled,
- ""
- }
- }
- };
-
- resource 'ICON' (kSplashID, "Splash icon") {
- $"0007 FF80 0008 0000 0008 7E20 0008 0120"
- $"0008 0120 0408 0120 0C08 0120 0808 0120"
- $"6608 0120 9908 0120 8108 FE20 8008 0020"
- $"8008 0020 4A00 1F20 3400 0020 00FC 0020"
- $"0300 0000 0401 FFF0 0400 0008 03E0 1FE4"
- $"0010 0552 0010 00A9 0020 0001 0020 01FE"
- $"0018 0000 0000 0000 0000 0000 24C6 EE6E"
- $"3D28 4884 25E8 4E44 2528 4824 2526 4EC4"
- };
-
- ----------- how its used in our IApplication -------------------
- TMyApplication::IApplication()
- {
- ...
- TSplashScreen splashScreen (15);
- ...
- splashScreen.UpdateSplashScreen();
- ...
- splashScreen.UpdateSplashScreen();
- ...
- }
- ----------- code -------------------
- /****************************************************************************\
- * *
- * METHOD TSplashScreen *
- * Initialize the splashscreen Object. *
- * *
- * 1. To avoid heap fragmentation, we allocate space for the DialogRecord *
- * on the stack, as a local variable in this procedure, so that the *
- * dialog record *won't* be allocated as a non-relocatable block at *
- * the bottom of the heap. *
- * 2. If we were to pass NIL to GetNewCenteredDialog for the dStorage, *
- * then the call to GetNewDialog would allocate the dialog record as a *
- * non-relocatable block at the bottom of the heap leading to heap *
- * fragmentation during InitUMacApp's call to MoreMasters. *
- * *
- \****************************************************************************/
- TSplashScreen::TSplashScreen( short num_sections, Boolean want_goaway_screen)
- {
- DialogPtr gSplashDlog = (DialogPtr)&fSplashDlogRecord;
- if ((GetNewCenteredDialog(kSplashID, (Ptr)gSplashDlog, (GrafPtr)-1)))
- {
- /* indicator bar */
- GetDItem(gSplashDlog, kProgressBar, &fItemType, &fItem, &fBar);
-
- if (num_sections >= kMaxNumSplashScreenCalls) // range check
- num_sections = kMaxNumSplashScreenCalls;
- fNumInc = num_sections;
- fCount = 0;
- // -----
- // now build the boxe sizes that fill in the bar
- //
- short i, x = fBar.left, y = x, top = fBar.top, bot = fBar.bottom;
- short tot_len = fBar.right - fBar.left + 1;
- short size_inc = tot_len/fNumInc, // what % of total size to draw
- slop_inc = tot_len % fNumInc; // what to have to add to last draw
- // to fill the rest of the prog bar
- for (i=0; i < fNumInc; i++) // build boxes to draw
- {
- y += size_inc + (i == fNumInc-2 ? slop_inc : 0);
- fBarPiece[i].top = top;
- fBarPiece[i].bottom = bot;
- fBarPiece[i].left = x;
- fBarPiece[i].right = y;
- }
- ShowWindow(gSplashDlog);
- DrawDialog(gSplashDlog);
-
- fWantGoAwayScreen = want_goaway_screen; // TRUE if user can click on splash
- // screen and make it go away
- }
- }
-
- /****************************************************************************\
- * *
- * METHOD UpdateSplashScreen *
- * Draws the next bar increment in the splash screen. *
- * *
- \****************************************************************************/
- pascal void TSplashScreen::UpdateSplashScreen()
- {
- EventRecord theEvent;
- if (GetNextEvent(mDownMask,&theEvent)) // Was a mouse down in cancel button?
- {
- if (IsDialogEvent(&theEvent)) // see if the mouse down was in a dialog
- {
- // assume (for now) that the only dialog event would be a mouse click
- // in this splash screen (that isn't 100% certain in a multi-finder
- // enviroment, but it'll do for now. Assume further that if the
- // dialog is clicked on anywhere (not only in the "cancel" button,
- // that the user wants the dialog to disappear
- //
- fCount = fNumInc; // set so updates won't occur
- HideWindow((DialogPtr)&fSplashDlogRecord);
- }
- }
- if (fCount < fNumInc) // don't do…should only fail if some one called a new
- { // UpdateSplashScreen() and didn't update the # of members to call (in
- // the init section)
- HLock((Handle)this);
- GrafPtr curGraphPort;
- GetPort (&curGraphPort);
- SetPort ((DialogPtr)&fSplashDlogRecord);
-
- EraseRect(&fBar);
- FrameRect(&fBar);
- FillRect(&fBarPiece[fCount++],qd.gray);
- SetPort(curGraphPort);
- HUnlock((Handle)this);
- }
- }
-
-